package com.example.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.custom.image.FeedImageView;
import com.example.taigame.MyApp;
import com.example.taigame.R;
import com.example.utils.Utils;

public class main_fragment_adapter extends BaseAdapter{

	private Context context;
	private int position;
	
	public main_fragment_adapter(Context context, int position) {
		this.context = context;
		this.position = position;
	}
	@Override
	public int getCount() {
		return MyApp.listGameType.get(position).getListGame().size();
	}

	@Override
	public Object getItem(int position) {
		return MyApp.listGameType.get(this.position).getListGame().get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	private static final String TAG = "main_fragment_adapter";

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (vi == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			vi = inflater.inflate(R.layout.gridview_item, null);
			FeedImageView image = (FeedImageView) vi.findViewById(R.id.imageView1);
			TextView gameName = (TextView) vi.findViewById(R.id.textView1);
			TextView download = (TextView) vi.findViewById(R.id.textView3);
			Log.w(TAG,Utils.LINK_IMAGE+MyApp.listGameType.get(this.position).getListGame().get(position).getLinkAvartar());
			image.setImageUrl(Utils.LINK_IMAGE+MyApp.listGameType.get(this.position).getListGame().get(position).getLinkAvartar());
			gameName.setText(MyApp.listGameType.get(this.position).getListGame().get(position).getName());
			download.setText(MyApp.listGameType.get(this.position).getListGame().get(position).getDownload()+" lượt tải");
		}
		return vi;
	}

}
